import socket  

address = ('localhost', 31500)  
class Server():
    def __init__(self):
        s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)  
        s.bind(address)  
 
    def run(self): 
        while True:  
            data, addr = s.recvfrom(2048)  
            print "client has exist"  
            if not data:  
                break  
            print "received:", data, "from", addr  

        s.close() 
  

class Client():
    def __init__(self):
        s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
        s.connect(address)

    def run(self):
        while True:  
            msg = raw_input() 
            s.sendto(msg, address) 
            if  msg == "q":  
                break  
